﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;

namespace WMI.NET.OperatingSystem.Users
{
    /// <summary>
    /// The Win32_UserAccount WMI class contains information about a user account on a computer system running Windows.
    /// Note  Because both the Name and Domain are key properties, enumerating Win32_UserAccount on a large network can negatively affect performance. Calling GetObject or querying for a specific instance has less impact.
    /// </summary>
    public class Win32_UserAccount : Win32_Account
    {

        private Nullable<UInt32> _AccountType;
        private Nullable<Boolean> _Disabled;
        private string _FullName;
        private Nullable<Boolean> _Lockout;
        private Nullable<Boolean> _PasswordChangeable;
        private Nullable<Boolean> _PasswordExpires;
        private Nullable<Boolean> _PasswordRequired;

        /// <summary>
        ///  Flags that describe the characteristics of a Windows user account.
        /// </summary>
        public Nullable<UInt32> AccountType { get { return _AccountType; } } //TODO enum

        /// <summary>
        /// Windows user account is disabled.
        /// </summary>
        public Nullable<Boolean> Disabled { get { return _Disabled; } set { throw new NotImplementedException(); } }

        /// <summary>
        /// Full name of a local user, for example: "Dan Wilson".
        /// </summary>
        public string FullName { get { return _FullName; } set { throw new NotImplementedException(); } }

        /// <summary>
        /// If true, the user account is locked out of the Windows operating system.
        /// </summary>
        public Nullable<Boolean> Lockout { get { return _Lockout; } set { throw new NotImplementedException(); } }

        /// <summary>
        /// If true, the password on this user account can be changed.
        /// </summary>
        public Nullable<Boolean> PasswordChangeable { get { return _PasswordChangeable; } set { throw new NotImplementedException(); } }

        /// <summary>
        /// If true, the password on this user account expires.
        /// </summary>
        public Nullable<Boolean> PasswordExpires { get { return _PasswordExpires; } set { throw new NotImplementedException(); } }

        /// <summary>
        /// If true, a password is required on a Windows user account. If false, this account does not require a password.
        /// </summary>
        public Nullable<Boolean> PasswordRequired { get { return _PasswordRequired; } set { throw new NotImplementedException(); } }


        /// <summary>
        /// The Rename WMI class method renames a user account name. This functionality is implemented as a method to provide a separate context for the new name that is distinguishable from the key property value for Name that is associated with the instance to be modified.
        /// </summary>
        /// <param name="Name">New account name.</param>
        /// <returns></returns>
        public UInt32 Rename(string Name) { throw new NotImplementedException(); } //TODO enum


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_UserAccount(ManagementBaseObject mbo)
            : base(mbo)
        {
            _AccountType = mbo.GetUIntValue("AccountType");
            _Disabled = mbo.GetBoolValue("Disabled");
            _FullName = mbo.GetStringValue("FullName");
            _Lockout = mbo.GetBoolValue("Lockout");
            _PasswordChangeable = mbo.GetBoolValue("PasswordChangeable");
            _PasswordExpires = mbo.GetBoolValue("PasswordExpires");
            _PasswordRequired = mbo.GetBoolValue("PasswordRequired");
        }

    }


    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_UserAccounts : Win32Collection<Win32_UserAccount>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_UserAccount> GetCollection()
        {
            List<Win32_UserAccount> tempCollection = new List<Win32_UserAccount>();

            foreach (var s in searcher.Get())
            {
                Win32_UserAccount tempListItem = new Win32_UserAccount(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_UserAccounts() : base("SELECT * FROM Win32_UserAccount") { }

    }

}
